package CCRMServer.Controllers;

import java.sql.Connection;
import java.sql.SQLException;

import java.sql.ResultSet;

import CCRMServer.DBConnect;
import Common.SERVER_COMMANDS;
import Common.ServerAnswer;
import Common.Entities.CustomerResponse;

/**
 * This class is to manage responses from the server side.
 * @author Ola
 * @author Al
 *
 */
public class ServerResponsesManagement {
/**
 * This method is for adding a new response to the DB.	
 * @param response the response of the customer.
 * @return ServerAnswer
 */
	public static ServerAnswer addResponse(CustomerResponse response){
		
		Connection conDB = DBConnect.mySQLConnection();
		
		String[] fields = {"customerID", "saleID", "responseType", "responseRefusalDescription", "responseDate","productID","responseDuration"};
		String[] values = {response.getCustomerID(), response.getSaleID(), response.getResponseType(), response.getResponseRefusalDescription(), 
				response.getResponseDate().toString(), Integer.toString(response.getProductID()),response.getResponseDuration()};
		try {
			
			Boolean isOK = DBConnect.insertSingleRecord(conDB, "CustomersResponses", fields, values);
			if (isOK)
				return new ServerAnswer(SERVER_COMMANDS.ADD_RESPONSE, null, "Add succeeded");
			return null;
			
		} catch (SQLException e) {
			return new ServerAnswer(SERVER_COMMANDS.ADD_RESPONSE, null, "DB Problem");
		}
	}
	
		

	

}
